package fhq.hcmute.edu.vn.adapter;

import android.net.wifi.WifiConfiguration;
import fhq.hcmute.edu.vn.activities.R;

/**
 * @author Hien Nguyen Oct 5, 2012
 */
public class WiFiItem {

	private String name;
	private int signal;
	private static String nameSignal;
	private String capabilities;
	private int securityType;

	private boolean isConnected = false;

	public final boolean isConnected() {
		return isConnected;
	}

	public final void setConnected(boolean isConnected) {
		this.isConnected = isConnected;
	}

	private static int[][] wifiSignal = new int[][] { { 40, 55 }, { 56, 65 },
			{ 66, 75 } };

	public static int getImage(int signalStrength) {
		signalStrength = Math.abs(signalStrength);
		if (signalStrength >= wifiSignal[0][0]
				&& signalStrength <= wifiSignal[0][1]) {
			return R.drawable.wifi_excellent;
		} else if (signalStrength >= wifiSignal[1][0]
				&& signalStrength <= wifiSignal[1][1]) {
			return R.drawable.wifi_good;
		} else if (signalStrength >= wifiSignal[2][0]
				&& signalStrength <= wifiSignal[2][1]) {
			return R.drawable.wifi_fair;
		}
		return R.drawable.wifi_poor;
	}

	public final String getNameSignal() {
		return nameSignal;
	}

	public final void setNameSignal(String nameSignal) {
		WiFiItem.nameSignal = nameSignal;
	}

	public final int getSecurityType() {
		return securityType;
	}

	public final String getName() {
		return name;
	}

	public final void setName(String name) {
		this.name = name;
	}

	public final int getSignal() {
		return signal;
	}

	public final void setSignal(int signal) {
		this.signal = signal;
	}

	public final String getCapabilities() {
		return capabilities;
	}

	public final void setCapabilities(String capabilities) {
		this.capabilities = capabilities;
	}

	/**
	 * @param name
	 * @param signal
	 * @param capabilities
	 */
	public WiFiItem(String name, int signal, String capabilities) {
		super();
		this.name = name;
		this.signal = getImage(signal);
		this.capabilities = capabilities;
		if (capabilities.contains("WPA")) {
			// WPA encryption
			this.securityType = WifiConfiguration.KeyMgmt.WPA_PSK;
		} else if (capabilities.contains("WEP")) {
			// WEP encryption
			this.securityType = WifiConfiguration.KeyMgmt.IEEE8021X;
		} else if (capabilities.contains("EES")) {
			// Open WiFi
			this.securityType = WifiConfiguration.KeyMgmt.NONE;
		}
	}

}
